package juhouse.glb.area.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import juhouse.framework.tools.DoText;
import juhouse.framework.tools.JuHouseCookie;
import juhouse.glb.area.dao.IpDao;

import org.apache.struts.actions.DispatchAction;

public class IpAction extends DispatchAction{

	public void visitedIP(HttpServletRequest request,HttpServletResponse response)
	{
		DoText myDoText = new DoText();
    	JuHouseCookie cookie = new JuHouseCookie();
		String areaId = cookie.getAreaId(request);
		if(areaId==null)
		{
			areaId = cookie.getAreaId(request,response);
		}
		String ip = request.getRemoteAddr();
		String page = request.getRequestURI();
		String parameter = request.getQueryString();
		if(parameter!=null)
		{
			page = page+"?"+parameter;
		}
		if(page.length()>120)
		{
			
			page = myDoText.left(page, 120);
		}
		String comPage = request.getHeader("Referer");
		if(comPage!=null&&comPage.length()>380)
		{
			comPage = myDoText.left(comPage, 380);
		}
		IpDao dao = new IpDao();
		dao.newVisitedIP(areaId, ip, page,comPage);
	}
	public boolean isDenyIP(HttpServletRequest request,String ip1,String ip2)
	{
		boolean flag = false;
		String ip = request.getRemoteAddr();
		IpDao dao = new IpDao();
		flag = dao.isDenyIP(ip, ip1, ip2);
		return flag;
	}
	public boolean isDenyCity(HttpServletRequest request,String city)
	{
		boolean flag = false;
		String ip = request.getRemoteAddr();
		IpDao dao = new IpDao();
		flag = dao.isDenyCity(ip, city);
		return flag;
	}
}
